package zust.itee.se;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class User implements UserI {
    @Value("${user.id}")
    private int id;
    @Value("${user.name}")
    private String name;
    @Autowired
    //@Qualifier("group2")
    private  GroupI group2;

    @Override
    public String toString() {
        return "id="+id+",name="+name+",我的组："+group2.info();
    }
    public String info(){
        return "id="+id+",name="+name+",我的组："+group2.info();
    }
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public GroupI getGroup2() {
        return group2;
    }

    public void setGroup2(GroupI group) {
        this.group2 = group;
    }
    @PostConstruct
    public void init(){
        System.out.println("create user:"+id);

    }
    @PreDestroy
    public  void destroy(){
        System.out.println("destroy user:"+id);
    }
}
